package com.nervenets.web.hibernate.domain.film;

import com.nervenets.utils.JodaUtils;
import com.nervenets.utils.StringUtils;
import com.nervenets.web.enumeration.MovieInfoStatus;
import com.nervenets.web.enumeration.MovieStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class MovieInfo implements Serializable {
    private String title;//主标题
    private String subtitle;//副标题
    private long priceOfUnit;//单份价格
    private int userLimit;//用户最大购买数量
    private long deposit;//是否支持线上定金线下购买
    private String coverImage;//封面图
    private List<String> carousels = new ArrayList<>();//轮播图
    private String content;//详情内容
    private String incomeDetail;//收益说明
    private String contractDetail;//合同说明
    private String riskWarning;//风险提示
    private List<MoviePriceChange> priceChanges = new ArrayList<>();//价格变动记录
    private List<MovieStatusChange> statusChanges = new ArrayList<>();//状态变动记录
    private BigDecimal profit;//每元收益，当状态为待收益时，该值存在表示需要确认审核
    private String profitFailedReason;//每元收益审核失败原因

    public void addPriceChange(long userId, long before, long after) {
        this.priceChanges.add(new MoviePriceChange(JodaUtils.getTimestamp(), userId, before, after));
    }

    public void addStatusChange(long userId, MovieStatus before, MovieStatus after) {
        this.statusChanges.add(new MovieStatusChange(JodaUtils.getTimestamp(), userId, before, after));
    }

    public boolean isValid() {
        return !StringUtils.isEmpty(title);
    }
}
